package com.example.bootkafka1.common;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.text.MessageFormat;
import java.util.Optional;

@Component
public class KafkaConsumer {

    private static Logger logger = LoggerFactory.getLogger(KafkaConsumer.class);

    @KafkaListener(topics = {"dyg"},group = "bootkafka1-group")
    public void listener(String data){
        logger.info(MessageFormat.format("接收到的消息：{0}",data));
    }


//    @KafkaListener(topics = {"dyg"},group = "bootkafka1-group")
//    public void listener (ConsumerRecord<?, ?> record) {
//        Optional<?> value = Optional.ofNullable(record.value());
//        if (value.isPresent()) {
//            logger.info(MessageFormat.format("接收到的消息：{0}", value.get()));
//        }
//    }
}
